﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<link rel="stylesheet" type="text/css" href="style/css/index.css" />
	<script type="text/javascript" src="${fp}/style/js/jquery.js"></script>
</head>

<body style="text-align: center">
	<div id="all">
		<div id="menu">
			<!-- 餐车div -->
			<div id="count">
				<table align="center" width="100%">
					<tr height="40">
				 		<td align="center" width="20%">菜名</td>
				 		<td align="center" width="20%">单价</td>
				 		<td align="center" width="20%">数量</td>
				 		<td align="center" width="20%">小计</td>
				 		<td align="center" width="20%">操作</td>
				 	</tr>
					<!--遍历餐车-->
					<c:forEach items="${front_cart}" var="cartItem">
					<tr height="60">
					 		<td align="center" width="20%">${cartItem.foodName}</td>
					 		<td align="center" width="20%">￥${cartItem.foodPrice}</td>
					 		<td align="center" width="20%">
								<input type="text" value="${cartItem.num}" size="3" lang="3" onchange="update(this,${cartItem.foodId},this.value)" />
					 		</td>
					 		<td align="center" width="20%">${cartItem.totalPrice}</td>
					 		<td align="center" width="20%">
								<input type="button" value="删除" class="btn_next" lang="3" onclick="delfood(this,${cartItem.foodId})" />
					 		</td>
				 	</tr>
					</c:forEach>

					<tr>
						<td colspan="6" align="right">总计:
							<span style="font-size:36px;">&yen;&nbsp;<span id="fprice" style="font-size:36px;">${final_price}</span></span>
							<label
									id="counter" style="font-size:36px"></label>
						</td>
					</tr>
					<tr>
						<td colspan="6" style="margin-left: 100px; text-align: center;"align="right">
							<input type="hidden" name="bId" value="">

							<input type="button" value="下单" class="btn_next" onclick="genernateOrder()" />
								
							
						</td>
					</tr>
				</table>
			</div>
		</div>

		<!-- 右边菜系列表，菜品搜索框  -->
		<div id="dish_class">
			<div id="dish_top">
				<ul>
					<li class="dish_num"></li>
					<li>
						<a href="clientOrderList.jsp">
							<img src="style/images/call2.gif" />
						</a>
					</li>
				</ul>
			</div>

			<div id="dish_2">
				<ul>
					<c:forEach items="${sessionScope.foodType}" var="foodType">
						<li>
							<a href="/front?method=findFoodByPage&typeName=${foodType.typeName}">${foodType.typeName}</a>
						</li>
					</c:forEach>
				</ul>
			</div>

			<div id="dish_3">
				<!-- 搜索菜品表单  -->
				<form action="/front?method=findFoodByPage" method="post">
					<table width="166px">
						<tr>
							<td>
								<input type="text" id="dish_name" name="foodName" class="select_value" value="${foodName}" />
							</td>
						</tr>
						<tr>
							<td><input type="submit" id="sub" value="" /></td>
						</tr>
						<tr>
							<td>
								<a href="/front?method=findFoodByPage">
									<img src="${fp}/style/images/look.gif" />
								</a>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</body>
<script>
	function delfood(obj,foodId) {
		var url="/foodcart?method=deleteByFoodId&foodId="+foodId;
		$.post(url,null,function (result) {
			if (result.success){
				$("#fprice").text(result.finalprice);
				$(obj).parent().parent().remove();
			}else{
				alert("删除失败");
			}
		}, "json");
	}
	function update(obj,foodId,val) {
		var url="/foodcart?method=updateByFoodId&foodId="+foodId+"&num="+val;
		$.post(url,null,function (result) {
			if (result.success){
				$("#tprice").text(result.toprice);
				$("#fprice").text(result.finalprice);
			}else{
				alert("修改失败");
			}
		}, "json");
	}
	function genernateOrder() {
		location.href="/order?method=generateOrder";
	}
</script>
</html>
